package com.eascs.afterloan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.api.form.O2oAfterLoanForm;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.afterloan.service.BankCardService;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;
import com.eascs.workflow.common.entity.sys.ActOrgEntity;
import com.eascs.workflow.common.service.sys.SysOrgService;

/**
 * @ClassName: BankCardController
 * @Description: 银行卡信息管理
 * @author 张庆奇
 * @date 2017年6月6日 上午10:18:07
 * @version V1.0
 */
@Controller
@RequestMapping("/bankCard")
public class BankCardController extends BaseMasterViewController {
	@Autowired
	BankCardService bankCardService;
	@Reference
	SysOrgService sysOrgService;
//	@Override
//	public void preHandle() {
//		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "loanManage1");
//	}

	@SuppressWarnings("unused")
	@RequestMapping(value = "/list")
	public String list(O2oAfterLoanForm entity) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "bankCard");
		List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();
		ViewContext.put("ActOrgEntitys", orgProvince);
		entity.setPageSize(10);
		String url = "/bankCard/list";
		if (null != entity) {
			String billCode = entity.getBillCode() == null ? "" : entity.getBillCode();
			String name = entity.getLoanUserName() == null ? "" : entity.getLoanUserName();
			url = UrlUtil.appendUrl(url, "billCode", billCode);
			url = UrlUtil.appendUrl(url, "loanerName", name);
			String createDateStart = entity.getCreateDateStart() == null ? "" : entity.getCreateDateStart();
			String createDateEnd = entity.getCreateDateEnd() == null ? "" : entity.getCreateDateEnd();
			url = url + "&o2oIndex=";
		} else {
			url = url + "?o2oIndex=";
		}
		PageResult<Object[]> pageResult = bankCardService.findByPageList(entity);
	
		String[] titles = { "贷款单号","省区" ,"借款人姓名",  "证件号码","送审银行","银行卡账户名" ,"银行卡号", "开户行"};
		SelectDataOption[] selectDataOptions = {null, null,null,null,new SelectDataOption("BANKTYPEO2O"),  null, null,null};
		Button[] findButton = new Button[] { ButtonHelper.createAjaxButton(null, "/rbankCard/detail?billCode=") };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, url);
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setTitleButtons(findButton);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(0);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", entity);
		return "/bankCard/index";
	}
	@RequestMapping(value = "/bank_card_info")
	public String bank_card_info(O2oAfterLoanForm entity) {
		
		entity.setPageSize(10);
		String url = "/bankCard/bank_card_info";
		url = url + "?o2oIndex=";
		
		PageResult<Object[]> pageResult = bankCardService.findBankCardByPageList(entity);
	
		String[] titles = { "姓名",  "证件号码" ,"银行卡号", "开户行","导入结果"};
		;
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, url);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(0);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", entity);
		return "/bankCard/bank_card_info";
	}
	
	
}
